package com.simple.ds.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Preconditions;
import com.simple.common.entity.po.ChannelMerchantEntity;
import com.simple.common.entity.po.MerchantApiChannelEntity;
import com.simple.ds.mapper.ChannelMerchantMapper;
import com.simple.ds.service.ChannelMerchantService;
import com.simple.ds.service.MerchantApiChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author yasud
 * @date 2021年09月17日 15:33
 * @description
 */
@Service
public class ChannelMerchantServiceImpl extends ServiceImpl<ChannelMerchantMapper, ChannelMerchantEntity> implements ChannelMerchantService {

    @Autowired
    MerchantApiChannelService merchantApiChannelService;

    @Override
    public ChannelMerchantEntity findByMerchantCodeAndApiCode(String merchantCode, String apiCode) {
        MerchantApiChannelEntity merchantApiChannelEntity = merchantApiChannelService.findByMerchantCodeAndApiCode(merchantCode, apiCode);
        Preconditions.checkNotNull(merchantApiChannelEntity, "请检查是否配置渠道");
        ChannelMerchantEntity merchantEntity = getById(merchantApiChannelEntity.getChannelMerchantId());
        Preconditions.checkState(Objects.nonNull(merchantEntity) && merchantEntity.getEnabled(), "找不到渠道，或未启用");
        return merchantEntity;
    }
}
